#!/bin/bash
# Version 0.0.1
time=`date "+%Y-%m-%d-%H"`

#num=`tail -1000 /var/log/httpd/access_log.$time | awk '{print $9}' | grep -v 200|grep -v 304|grep -v 302|wc -l`
num=`tail -1000 /var/log/nginx/access.log | awk '{print $9}' | grep -v 200|grep -v 304|grep -v 302|wc -l`

# Getting parameters:
while getopts "w:c:h" OPT;do
case $OPT in
"w")warning=$OPTARG;;
"c")critical=$OPTARG;;
"h")help;;
esac
done

#Comparing the result and setting the correct level:
if [[ $num -ge $critical ]]; then
	msg="CRITICAL"
	status=2
else if [[ $num -ge $warning ]]; then
	msg="WARNING"
	status=1
else
	msg="OK"
	status=0
    fi
fi

#Printing the results:
echo "$msg - Http Request Rresponse_Code Not-200 Num $num"

exit $status
